<?php
include("config.php");

// 验证是否为 AJAX 请求
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || $_SERVER['HTTP_X_REQUESTED_WITH'] !== 'XMLHttpRequest') {
    die("非法请求");
}

// 获取书籍 ID
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id === 0) {
    header('Content-Type: application/json');
    echo json_encode(['status' => 'error', 'message' => '缺少书籍ID']);
    exit;
}

// 执行删除操作
$sql = "DELETE FROM info_book WHERE id = $id";
$result = mysqli_query($connect, $sql);

if ($result) {
    header('Content-Type: application/json');
    echo json_encode(['status' => 'success', 'message' => '删除成功']);
} else {
    header('Content-Type: application/json');
    echo json_encode(['status' => 'error', 'message' => '删除失败：' . mysqli_error($connect)]);
}
mysqli_close($connect);
?> 